package com.yxj.Practice2;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {
        //1.创建ServerSocket对象并绑定端口10000
        ServerSocket ss = new ServerSocket(10000);

        //2.等待客户端链接
        Socket socket = ss.accept();

        //3.socket中获取输入流读取数据
        InputStream is = socket.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        int b;
        while((b = isr.read()) != -1) {
            System.out.print((char)b);
        }

        //4.回写数据
        String str = "有多开心";
        OutputStream os = socket.getOutputStream();
        os.write(str.getBytes());

        //
        socket.close();
        ss.close();
    }
}
